package com.pengke.pangu.controller.basic;

import cn.hutool.core.util.RandomUtil;
import com.pengke.pangu.common.oss.qiniu.QiniuUtil;
import com.pengke.pangu.common.utils.R;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.io.InputStream;

@Slf4j
@RestController
public class FileController {

    @Resource
    private QiniuUtil qiniuUtil;

    @PostMapping("/upload")
    public R upload(@RequestParam("file")MultipartFile file) throws IOException {
        InputStream inputStream = file.getInputStream();
        String url = qiniuUtil.upload(inputStream, RandomUtil.randomString(32));
        log.info("url:{}", url);
        return  R.ok(url);
    }
}
